package com.tom.architect.party3.day27.simple2;

import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.Response;

public class CacheResponseInterceptor implements Interceptor {

    @Override
    public Response intercept(Chain chain) throws IOException {
        Response response = chain.proceed(chain.request());
        // 过期时间是30s.  30s内不需要重新请求网络。客户端自己定义的规则。
        response = response.newBuilder()
                .removeHeader("Cache-Control")
                .removeHeader("Pragma")
                .addHeader("Cache-Control","max-age="+30).build();
        return response;
    }
}
/**
 * 30s内请求同一个接口，读取缓存 ，告诉Cache-Control。
 */